package com.tianyi.web;

import com.tianyi.domain.entity.MyUserEntity;
import com.tianyi.domain.services.MyUserSerice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/myuser")
public class MyUserControl {

    @Autowired
    MyUserSerice MyUserSerice;

    /**
     * 测试的方法
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public MyUserEntity saveUser() throws Exception {
        MyUserEntity myUser = new MyUserEntity();
        myUser.setUserName("wuzheyan");
        myUser.setContactInfo("xxxxxxx");
        myUser.setCreationDate(new Date());

        return MyUserSerice.insertMyUser(myUser);
    }

    // @RepeatAnnotation(interval = 50000, uniqueKey = {"userName"})
    @RequestMapping(value = "/saveUser", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public MyUserEntity saveUser(@RequestBody MyUserEntity myUser) throws Exception {
        MyUserEntity myUserEntity = MyUserSerice.insertMyUser(myUser);
        return myUserEntity;
    }
}
